package cn.yeziji.forum.config.auth;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;

/**
 * 用户登录 token
 *
 * @author gzkemays
 * @since 2021/12/21 18:07
 */
public class UserAuthenticationToken extends UsernamePasswordAuthenticationToken {
  private Object principal;
  private Object credentials;

  public UserAuthenticationToken(String username, String password) {
    super(username, password);
/*    ForumUserDao userDao = SpringUtils.getBean(ForumUserDao.class);
    ForumUserEntity userEntity = userDao.selectUserByUserName(username);
    if (userEntity == null && username != null && password != null) {
      UserRegisterBO bo =
          new UserRegisterBO(username, PasswordSecurity.generatedPassword(password));
      userDao.registerUser(bo);
    }*/
    this.principal = username;
    this.credentials = password;
  }

  @Override
  public Object getCredentials() {
    return credentials;
  }

  @Override
  public Object getPrincipal() {
    return principal;
  }

  @Override
  public void eraseCredentials() {
    super.eraseCredentials();
    this.credentials = null;
  }
}
